const mysql = require("mysql");

function query(sql, params = []) {
    // 创建数据库连接
    const con = mysql.createConnection({
        host: "localhost",
        user: "root",
        port: 3306,
        password: "root",
        database: "address",
    });

    return new Promise((resolve, reject) => {
        con.query(sql, params, (error, data) => {
            if (error) {
                reject(error);
            } else {
                resolve(data);
            }
        });

        con.end();
    });
}

module.exports = { query };
